#ifndef prs_Func_H
#define prs_Func_H

#include "prs_Attr.h"
#include "sntText.h"

namespace prs { 

///////////////////////////////////////////////////////////////////////////////
/************
struct TFVoidNewNode : public svl::TPointer
{
  TFVoidNewNode(svl::TVariant &VParentNode,prs::TNode &NodeType);
 ~TFVoidNewNode() { delete nodeType;} 
  //
  snt::TFVoid &New() { return snt::TFVoid().New(Func,vThis);}

private:
  static void Func(snt::TParams &Params);
  //
  svl::TVariant &vParentNode,vThis;
  prs::TNode *nodeType;
};
*************************/

/**************
///////////////////////////////////////////////////////////////////////////////

struct TFVoidNewNode : public svl::TPointer
{
  TFVoidNewNode() { nodeType = NULL; vThis = this;}
 ~TFVoidNewNode() { delete nodeType;} 
  //
  static snt::TFVoid &New(svl::TVariant &VParentNode,TNode &NodeType,bool SetParent = true);

private:
  static void Func(snt::TParams &Params);
  //
  svl::TVariant *vParentNode,vThis;
  TNode *nodeType;
  bool setParent;
};
**********************/

///////////////////////////////////////////////////////////////////////////////

struct TFuncNewNodeIntoAttr : public svl::TPointer
{
  TFuncNewNodeIntoAttr() { nodeType = NULL; attrName = NULL;}
 ~TFuncNewNodeIntoAttr() { delete nodeType;} 
  //
  static snt::TFVoid &New(
    svl::TVariant &VNode,
    svl::TString &AttrName,
    TAttrNode &NodeType,
    bool SetParent = true
  );
  static snt::TFVoid &New(
    svl::TVariant &VNode,
    const char *AttrName,
    TAttrNode &NodeType,
    bool SetParent = true
  );

private:
  void Func(snt::TParams &Params);
  //
  svl::TVariant *vNode;
  svl::TString *attrName,defAttrName;
  TAttrNode *nodeType;
  bool setParent;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
/**********************
template<class AttrArray,class NodeType> 
struct TFVoidNewNodeEx : public svl::TPointer
{
  TFVoidNewNodeEx() { vThis = this;}
 ~TFVoidNewNodeEx() { } 
  //
  static snt::TFVoid &New(
    svl::TVariant &VParentNode,
    bool SetParent = true
  )
  {
    TFVoidNewNodeEx *P = new TFVoidNewNodeEx;
      P->vParentNode = &VParentNode;
      P->setParent = SetParent;
    snt::TFVoid &F = snt::TFVoid().New(Func,P->vThis);
      F.SetExt(P);
    return F;
  }

private:
  static void Func(snt::TParams &Params)
  {
    TFVoidNewNodeEx *This = dynamic_cast<TFVoidNewNodeEx*>(Params[0].Pointer());
    prs::TAttrNode *ParentNode = dynamic_cast<TAttrNode*>(This->vParentNode->Pointer());
    NodeType *NewNode = new NodeType;

    //TAttrNodeArray<AttrName,ArrayType> *Attr = dynamic_cast< TAttrNodeArray<AttrName,ArrayType> *>(
    //  ParentNode->SearchAttr(AttrName)
    //);
    
    if (Attr) {
      ParentNode->AttrArray.Array.Add(NewNode,true);
    }
    else {
    
    }
    //ParentNode->Children_Add(NewNode,true);
    
    if (This->setParent) {
     *This->vParentNode = NewNode;
    }
  }
  //
  svl::TVariant *vParentNode,vThis;
  bool setParent;
};
*********************************/
///////////////////////////////////////////////////////////////////////////////
}

#endif
